//
//  RootViewController.m
//  UI16_UICollectionViewHomeWork
//
//  Created by dllo on 16/3/30.
//  Copyright © 2016年 XWH. All rights reserved.
//

#import "RootViewController.h"
#import "Header.h"
#import "RootCollectionViewCell.h"
@interface RootViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (nonatomic, strong) UICollectionView *collection;
@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor orangeColor];
    [self creatView];
}


-(void)creatView{
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    
    flowLayout.itemSize = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT/1.5);
    flowLayout.minimumInteritemSpacing = 0;
    flowLayout.minimumLineSpacing = 0;
    flowLayout.sectionInset = UIEdgeInsetsMake(50, 0, 50, 0);
    
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
   self.collection  = [[UICollectionView alloc] initWithFrame:SCREEN_BOUNDS collectionViewLayout:flowLayout];
    
    self.collection.delegate = self;
    self.collection.dataSource = self;
    
    self.collection.pagingEnabled = YES;
    [self.collection registerClass:[RootCollectionViewCell class] forCellWithReuseIdentifier:@"pool1"];
    
    self.collection.contentOffset = CGPointMake(SCREEN_WIDTH * _index.row, 0);
    [self.view addSubview:self.collection];
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return self.array.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    RootCollectionViewCell *cell = [self.collection dequeueReusableCellWithReuseIdentifier:@"pool1" forIndexPath:indexPath];
    self.model = [[ModelOfPicture alloc] init];
    
    cell.imageView.image = self.array[indexPath.item];
    
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
